﻿using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Red.Core.GoogleAnalytics;
using ViewModel = Red.Launcher.ViewModels.ExternalApplications;

namespace Red.Launcher
{
    public partial class ExternalApplicationsView
    {
        #region Private Data

        private readonly string _analyticsCategory = typeof( ExternalApplicationsView ).Name;

        #endregion Private Data

        #region Private Methods

        partial void InitializeAnalytics()
        {
            _addApplication.Click += _addApplication_ClickAnalytics;
            _applicationList.MouseDoubleClick += _applicationList_MouseDoubleClickAnalytics;
            _applicationList.SelectionChanged += _applicationList_SelectionChangedAnalytics;
        }

        #endregion Private Methods

        #region Event Handlers

        private void _addApplication_ClickAnalytics( object sender, RoutedEventArgs e )
        {
            GoogleAnalyticsService.Instance.SendEvent( "Add", _analyticsCategory );
        }

        private void _applicationList_MouseDoubleClickAnalytics( object sender, MouseButtonEventArgs e )
        {
            ViewModel.Application application = (ViewModel.Application)_applicationList.SelectedItem;

            if( application != null )
            {
                GoogleAnalyticsService.Instance.SendEvent( "Run", _analyticsCategory, application.Name );
            }
        }

        private void _applicationList_SelectionChangedAnalytics( object sender, SelectionChangedEventArgs e )
        {
            ViewModel.Application application = (ViewModel.Application)_applicationList.SelectedItem;

            if( application != null )
            {
                GoogleAnalyticsService.Instance.SendEvent( "Select", _analyticsCategory, application.Name );
            }
            else
            {
                GoogleAnalyticsService.Instance.SendEvent( "Deselect", _analyticsCategory );
            }
        }

        #endregion Event Handlers
    }
}
